package com.hangsu.train.components.web.controller;


import com.hangsu.train.components.entity.User;
import com.hangsu.train.components.params.CodeParam;
import com.hangsu.train.components.params.PageRequestParam;
import com.hangsu.train.components.service.UserService;
import com.hangsu.train.core.result.Err;
import com.hangsu.train.core.result.Resp;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lyy
 * @Date 2021/12/13
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    private UserService userService;

    @Resource
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    /**
     * 用户列表带翻页
     *
     * @param param
     * @return
     */
    @PostMapping("/list")
    public Resp<Page<User>> list(@RequestBody @Valid PageRequestParam param) {
        Page<User> page = userService.list(param);
        return Resp.ok(page);
    }

    /**
     * 根据code获取用户信息
     *
     * @param param
     * @return
     */
    @PostMapping("/info")
    public Resp getUserByUserCode(@RequestBody @Valid CodeParam param) {
        User user = userService.detail(param.getCode());
        return Resp.ok(user);
    }

}